﻿using UnityEngine;
using System.Collections;


public class BossCanTakeDamage : CanTakeDamage {

    private Transform Wave;
    private EnemyDifficultyManager difficulty;


	// Use this for initialization
    public float CurrencyDrop = 1000f;
    protected override void Start()
    {
        Wave = GameObject.FindGameObjectWithTag("WaveManager").transform;
        foreach (Transform child in Wave)
        {
            if (child.gameObject.activeInHierarchy)
            {
                difficulty = child.gameObject.GetComponent<EnemyDifficultyManager>();
            }
        }

        difficulty.Add(Health, difficulty.Health.Adder, out Health);
        difficulty.AddPercentage(Health, difficulty.Health.PercentageMultiplier, out Health);
        if (difficulty.Health.EqualToEnabled)
        {
            Health = Mathf.FloorToInt(difficulty.Health.EqualTo);
        }

        difficulty.Add(CurrencyDrop, difficulty.CurrencyDrop.Adder, out CurrencyDrop);
        difficulty.AddPercentage(CurrencyDrop, difficulty.CurrencyDrop.PercentageMultiplier, out CurrencyDrop);
        if (difficulty.CurrencyDrop.EqualToEnabled)
        {
            CurrencyDrop = (int)Mathf.Floor(difficulty.CurrencyDrop.EqualTo);
        }

        DealsDamage BulletDamage = null;
        if(gameObject.GetComponent<Hodor>() != null)
        {

            BulletDamage = gameObject.GetComponent<Hodor>().Bullet.GetComponent<DealsDamage>();

        }
        else if (gameObject.GetComponent<bossteleport>() != null)
        {
            BulletDamage = gameObject.GetComponent<bossteleport>().enemyRocket.GetComponent<DealsDamage>();
        }
        else if (gameObject.GetComponent<bosspieces>() != null)
        {
                BulletDamage = gameObject.GetComponent<bosspieces>().clusterBombLaunchers.GetComponent<DealsDamage>();
                difficulty.Add(BulletDamage.DamageOnCollision, difficulty.BulletDamageDealt.Adder, out BulletDamage.DamageOnCollision);
                difficulty.AddPercentage(BulletDamage.DamageOnCollision, difficulty.BulletDamageDealt.PercentageMultiplier, out BulletDamage.DamageOnCollision);
                if (difficulty.BulletDamageDealt.EqualToEnabled)
                {
                    BulletDamage.DamageOnCollision = (int)Mathf.Floor(difficulty.BulletDamageDealt.EqualTo);
                }

                BulletDamage = gameObject.GetComponent<bosspieces>().endBossRocketLaunchers.GetComponent<DealsDamage>();
                difficulty.Add(BulletDamage.DamageOnCollision, difficulty.BulletDamageDealt.Adder, out BulletDamage.DamageOnCollision);
                difficulty.AddPercentage(BulletDamage.DamageOnCollision, difficulty.BulletDamageDealt.PercentageMultiplier, out BulletDamage.DamageOnCollision);
                if (difficulty.BulletDamageDealt.EqualToEnabled)
                {
                    BulletDamage.DamageOnCollision = (int)Mathf.Floor(difficulty.BulletDamageDealt.EqualTo);
                }
                BulletDamage = gameObject.GetComponent<bosspieces>().endBossMainAmmo.GetComponent<DealsDamage>();
        }

        difficulty.Add(BulletDamage.DamageOnCollision, difficulty.BulletDamageDealt.Adder, out BulletDamage.DamageOnCollision);
        difficulty.AddPercentage(BulletDamage.DamageOnCollision, difficulty.BulletDamageDealt.PercentageMultiplier, out BulletDamage.DamageOnCollision);
        if (difficulty.BulletDamageDealt.EqualToEnabled)
        {
            BulletDamage.DamageOnCollision = (int)Mathf.Floor(difficulty.BulletDamageDealt.EqualTo);
        }
        base.Start();
    }

	public override void TakeDamage(int dmg)
	{
		ToggleShader();
		base.TakeDamage(dmg);
		Invoke("ToggleShader", .2f);
	}
	public void ToggleShader()
	{
		
		if (renderer.material.shader == Shader.Find("Transparent/Diffuse") || renderer.material.shader == Shader.Find("Transparent/Bumped Diffuse"))
		{
			//renderer.material.color = Color.red;
			renderer.material.shader = Shader.Find("Particles/Additive");
			
		}
		else if (renderer.material.shader == Shader.Find("Particles/Additive"))
		{
			//renderer.material.color = Color.white;
			print("go back");
			renderer.material.shader = Shader.Find("Transparent/Diffuse");
		}
	}
}
